<?php

if (!defined('IN_AJAX')) die(basename(__FILE__));

global $userdata, $ts_cfg, $lang;

$mode = (string) $this->request['mode'];

switch ($mode)
{
	case 'edit_blog_title':
		$blog_id     = (int) $this->request['blog_id'];
		$blog_title  = (string) $this->request['blog_title'];
		$new_title   = clean_title($blog_title);
		
		if (!$blog_id) $this->ajax_die($lang['INVALID_TOPIC_ID']);
		if ($new_title == '') $this->ajax_die($lang['DONT_MESSAGE_TITLE']);
		
		if (!$t_data = DB()->fetch_row("SELECT * FROM ". TS_BLOGS ." WHERE blog_id = $blog_id LIMIT 1"))
		{
			$this->ajax_die($lang['INVALID_TOPIC_ID_DB']);
		}
		
		$blog_title_sql = DB()->escape($new_title);
		
		DB()->query("UPDATE ". TS_BLOGS ." SET blog_title = '$blog_title_sql' WHERE blog_id = $blog_id LIMIT 1");
		
		$this->response['blog_id'] = $blog_id;
		$this->response['blog_title'] = $new_title;
		break;
}
